import React, {Component} from 'react';
//import pureRender from 'pure-render-decorator';
import {History, Link, browserHistory,hashHistory } from 'react-router';
import { connect } from 'react-redux';
import { logOut } from '../Redux/Actions/authAction';
import { is, fromJS} from 'immutable';
import {QiniuImgUrl} from './common/url';
import {Imglist} from './common/img';

const history = process.env.NODE_ENV !== 'production' ? browserHistory : hashHistory;

class Me extends Component {
    constructor() {
        super();
        this.loginout = ()=>{
            this.props.dispatch(logOut());
        }
    }

    shouldComponentUpdate(nextProps, nextState) {
        const {authReducer} = nextProps;
        if(authReducer.isLoggedIn == false){
            history.push("/");
            return false;
        }
    }
   
    render() {
        const user = this.props.authReducer.user.data;
        document.title="我的账户";
        return (
            <div className="main-wrap bg-grey">
                <div className="me-header">
                    <div className="header-img"></div>
                    <h3>{user.truename}<span className="badge bg-blue">已认证</span></h3>
                </div>
                <div className="me-info">
                    <ul className="infoList">
                        <li>
                            <span>手机号</span> <span>{user.phone}</span>
                        </li>
                        <li>
                            <span>QQ</span> <span>{user.qq}</span>
                        </li>
                        <Imglist src={user.identityUrl} alt="身份证"/>
                        <li>
                            <span>公司名称</span> <span>{user.company}</span>
                        </li>
                        <li>
                            <span>公司注册号</span> <span>{user.registerNo}</span>
                        </li>
                        <Imglist src={user.businessLicenseUrl} alt="公司营业执照"/>
                    </ul>
                    <div>
                        <button className="btn-primary" onClick={this.loginout}>注销</button>
                    </div>
                </div>
            </div>
        )
    }
}


export default connect((state) => {
    const { authReducer } = state;
    return {
        authReducer
    }
})(Me);